package com.lenovo.manufacture.module;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.lenovo.manufacture.BaseActivity;
import com.lenovo.manufacture.R;
import com.lenovo.manufacture.adapter.MyAdapter;
import com.lenovo.manufacture.annotation.Layout;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import butterknife.BindView;

public class Module7 extends BaseActivity {

    @BindView(R.id.rv_module7)
    RecyclerView rvModule7;
    List<Map<String, String>> cars;
    List<Map<String, String>> qualities;
    Map<String, String> stringMap = new HashMap<>();

    @Layout(value = R.layout.activity_module7, title = "问题车辆列表查询")
    protected void init() {
        async(apiService.userQuality(), data -> {
            qualities = data.getData();
            async(apiService.getCarType(), data1 -> {
                cars = data1.getData();
                async(apiService.getAllUserLine(), data2 -> {
                    for (Map<String, String> userLine : data2.getData()) {
                        stringMap.put(userLine.get("id"), userLine.get("userLineName"));
                    }
                    initList();
                });
            });
        });
    }

    private void initList() {
        List<String> strings = new ArrayList<>();
        qualities.forEach(quality -> {
            Map<String, String> car = cars.stream().filter(car1 -> car1.get("id").equals(quality.get("carTypeId"))).collect(Collectors.toList()).get(0);
            strings.add(String.valueOf(quality.get("id")));
            strings.add(car.get("carTypeName"));
            strings.add(car.get("content"));
            strings.add(stringMap.get(quality.get("userLineId")));
            strings.add(String.valueOf(car.get("repairPrice")));
        });
        rvModule7.setLayoutManager(new GridLayoutManager(this, 5));
        rvModule7.setAdapter(new MyAdapter(strings));
    }
}
